Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
How can I make "numbers" input uneditable in a matter of typing?

I know how to make numbers input completely read only. However, how do I make it typing locked? Since I can type in it endless numbers even though the max value is 10 (and it works but only when using this up and down thing). If there's any code needed let me know, although I don't think so

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use Javascript to check what the number's value is every time it changes, and if it's higher (or lower) than what you've specified, reset the value to the maximum or minium:

let number = document.getElementById("number");

let max = 10;
let min = 0;

number.addEventListener('input', () => {  

  if (number.value > max) {
    number.value = max;
  }
  
  if (number.value < min) {
    number.value = min;
  }

  
});
<input type="number" id="number" step="1" max="10" min="0">

about 4 years ago · Juan Pablo Isaza Relatório

0

Still use the number type since that will do at least some of the checking for you but catch the user's input and if the number would become too big go back to the previous value (i.e. ignore the most recent typed digit just as you would an a-z character).

let limitedInputs = document.querySelectorAll("input.limitedNumber");
let prevValue = 0;

limitedInputs.forEach(input => {
  input.addEventListener('input', () => {

    if (input.value > input.max) {
      input.value = prevValue;
    } else if (input.value < input.min) {
      input.value = input.min;
    } else {
      prevValue = input.value;
    }

  });
});
<input type="number" max="10" min="0" class="limitedNumber">

This snippet just sets the min value if the user's typed value goes too low but you may want to make the behavior different depending on the minimum value.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda